import Vue from 'vue'
import VueRouter from 'vue-router'
import LoginPlus from '../views/LoginPlus.vue'
import Role from '../components/menu/Role.vue'
import Permission from '../components/menu/Permission.vue'
import Users from '../components/menu/Users.vue'
import Test1 from '../components/menu/Test1.vue'
import Test2 from '../components/menu/Test2.vue'
import Test3 from '../components/menu/Test3.vue'
import crypto from '../crypto/crypto'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
Vue.use(VueRouter)

var mpath=[];
for(var i =1;i<70;i++){
  mpath[i]=crypto.set(i);
}

const routes = [
  {
    path: '/',
    name: 'loginplus',
    component: LoginPlus
  },
  {
    path: '/home/:key',
    name: 'Home',
    meta: { permission: true },
    beforeEnter: function(to, from, next) {
      console.log(to)
      console.log(from)
      console.log(next)
      if (sessionStorage.getItem("token")) {
        next();
      } else {
        // this.$message.info("请先登录");
        alert('请先登录')
        next("/");
      }
    },
    component: () => import(/* webpackChunkName: "about" */ '../views/Home.vue'),
    children: [
      { path: '/'+mpath[39], component: Role },
      { path: '/'+mpath[40], component: Permission },
      { path: '/'+mpath[38], component: Users },
      { path: '/test1', component: Test1 },
      { path: '/test2', component: Test2 },
      { path: '/test3', component: Test3 },
    ]
  },
]

const router = new VueRouter({
  routes
})

NProgress.configure({ showSpinner: true })
//在路由跳转前用NProgress.start()标记下进度条开始
router.beforeEach((to, from, next) => {
 NProgress.start()
 next()
});
 
//在路由跳转后用NProgress.done()标记下结束
router.afterEach(() => {
 NProgress.done()
})
export default router
